package com.situ.day14week;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Arrays;

import org.junit.Test;

public class Demo {
	@Test
	public void test1() {
		FileReader fileReader = null;
		try {
			fileReader = new FileReader("a.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				System.out.println(length);
				System.out.println(Arrays.toString(buffer));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fileReader != null) {
				try {
					fileReader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test2() {
		FileReader fileReader = null;
		FileWriter fileWriter = null;
		try {
			fileReader = new FileReader("a.txt");
			fileWriter = new FileWriter("b.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				fileWriter.write(buffer, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void test3() {
		FileInputStream fileInputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			fileInputStream = new FileInputStream("tupianxin.jpg");
			fileOutputStream = new FileOutputStream("tupianzuixin.jpg");
			int length = 0;
			byte[] buffer = new byte[1024];
			while ((length = fileInputStream.read(buffer)) != -1) {
				fileOutputStream.write(buffer, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fileInputStream != null) {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test4() {
		Student student = new Student(1, "张三", 24);
		FileOutputStream fileOutputStream = null;
		ObjectOutputStream objectOutputStream = null;
		try {
			fileOutputStream = new FileOutputStream("studentss");
			objectOutputStream = new ObjectOutputStream(fileOutputStream);
			objectOutputStream.writeObject(student);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void test5() {
		FileInputStream fileInputStream = null;
		ObjectInputStream objectInputStream = null;
		try {
			fileInputStream = new FileInputStream("studentss");
			objectInputStream = new ObjectInputStream(fileInputStream);
			Object object = objectInputStream.readObject();
			Student student = (Student)object;
			System.out.println(student);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void test6() {
		String regex = "[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+";
		String str = "1040565173@qq.com";
		if (str.matches(regex)) {
			System.out.println("是邮箱");
		} else {
			System.out.println("不是邮箱");
		}
	}
	@Test
	public void test7() {
		String regex = "\\d+";
		String str = "asdasdasd21sadasd1asd1asd123ddd";
		String[] array = str.split(regex);
		for (String string : array) {
			System.out.println(string);
		}
	}
	@Test
	public void test8() {
		GenderCL genderCL1 = new GenderCL(1, "张三", Gender.male);
		GenderCL genderCL2 = new GenderCL(2, "李四", Gender.male);
		if (genderCL1.getGender() == genderCL2.getGender()) {
			System.out.println("性别一样");
		}else {
			System.out.println("性别不同");
		}
	}
	@Test
	public void test9() {
		EnumDemo enumDemo = EnumDemo.male;
		System.out.println(enumDemo);
		System.out.println(enumDemo.getValue());
	}

}
